#include <Def.h>
#include <qtextstream>
#include <qdebug.h>
#include <qstringlist.h>
#include <qtextstream.h>
#include "Viewpoint.h"

Viewpoint Viewpoint::fromString(const QString& string)
{
	Viewpoint point;
	{
		QTextStream stream(string.toLocal8Bit());
		stream >>point.name;
		stream.skipWhiteSpace();
		stream >>point.lon;
		stream.skipWhiteSpace();
		stream >>point.lat;
		stream.skipWhiteSpace();
		stream >>point.alt;
		stream.skipWhiteSpace();
		stream >>point.heading;
		stream.skipWhiteSpace();
		stream >>point.pitch;
		stream.skipWhiteSpace();
		stream >>point.distance;
		point.distance = std::max(std::min(10e8,point.distance),10.0);
		qDebug()<<point.name<<"."<<point.lon<<"."<<point.heading<<"."<<point.distance;
	}

	return point;
}

Viewpoint::Viewpoint()
{
}

Viewpoint::Viewpoint(const Viewpoint& rhs):
name(rhs.name),
lon(rhs.lon),
lat(rhs.lat),
alt(rhs.alt),
heading(rhs.heading),
pitch(rhs.pitch),
distance(rhs.distance)
{
}

Viewpoint::~Viewpoint()
{
}

bool Viewpoint::isValid()const
{
    return distance > 1000.0;
}

QString Viewpoint::toString()const
{
	return QString("%1 %2 %3 %4 %5 %6 %7")
		.arg(name)
		.arg(lon)
		.arg(lat)
		.arg(alt)
		.arg(heading).arg(pitch).arg(distance);
}